package com.yh.services.impl;

import com.yh.dao.IDirtyWordMapper;
import com.yh.entity.Dirty;
import com.yh.services.IDirtyWordService;
import com.yh.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class DirtyWordServiceImpl implements IDirtyWordService {
    SqlSession sqlsession = SqlSessionFactoryUtil.getSqlsession();
    IDirtyWordMapper mapper = sqlsession.getMapper(IDirtyWordMapper.class);
    @Override
    public String  getAll(String str) {
        List<Dirty> list= mapper.getAll();
        for (Dirty d:list) {
            if (str.indexOf(d.getSpeak())!=-1){
                str=str.replace(d.getSpeak(),"*");
            }
        }
        return str;
    }
}
